CREATE TABLE [dbo].[tb_Proveedores]
(
[idProveedor] [int] NOT NULL IDENTITY(1, 1),
[RazonSocial] [varchar] (60) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[CUIT] [varchar] (13) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[CondicionFiscal] [int] NOT NULL,
[Domicilio] [varchar] (100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[Localidad] [int] NOT NULL,
[Telefono] [varchar] (30) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[Interno] [varchar] (10) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[Fax] [varchar] (30) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[Movil] [varchar] (30) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[E-Mail] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[Web] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[IngresosBrutos] [varchar] (20) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[Contacto] [varchar] (60) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[TelefonoContacto] [varchar] (30) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[MovilContacto] [varchar] (30) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[E-MailContacto] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL
) ON [PRIMARY]
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE TRIGGER [dbo].[updatetb_Proveedores] ON [dbo].[tb_Proveedores]
 FOR UPDATE AS 
 IF (update(idProveedor)) begin 
	 SELECT * FROM inserted 
	 IF @@ROWCOUNT = 1 begin 
		 UPDATE tb_RegistroContable
		 SET Proveedor = (SELECT idProveedor FROM inserted)
		 WHERE tb_RegistroContable.Proveedor = (SELECT idProveedor FROM deleted)
	end  ELSE begin 
		 ROLLBACK TRANSACTION 
 end 
 end
GO
ALTER TABLE [dbo].[tb_Proveedores] ADD CONSTRAINT [PK_tb_Proveedores] PRIMARY KEY NONCLUSTERED  ([idProveedor]) ON [PRIMARY]
GO
ALTER TABLE [dbo].[tb_Proveedores] WITH NOCHECK ADD CONSTRAINT [FK_tb_Proveedores_Tb_CondicionesFiscales] FOREIGN KEY ([CondicionFiscal]) REFERENCES [dbo].[Tb_CondicionesFiscales] ([IdCondicionFiscal])
GO
ALTER TABLE [dbo].[tb_Proveedores] WITH NOCHECK ADD CONSTRAINT [FK_tb_Proveedores_tb_Localidades] FOREIGN KEY ([Localidad]) REFERENCES [dbo].[tb_Localidades] ([idLocalidad]) NOT FOR REPLICATION
GO
ALTER TABLE [dbo].[tb_Proveedores] NOCHECK CONSTRAINT [FK_tb_Proveedores_tb_Localidades]
GO
